/**
* @Author: zmx
* @Date: 2023/9/25
* @Description:
*/
<template>
  <div style="padding: 20px">
    <el-form :inline="true" :model="formInline">
      <el-form-item>
        <el-button type="primary" icon="el-icon-plus" @click="addPlan">新建方案</el-button>
      </el-form-item>
      <el-form-item label="方案名称：">
        <el-input v-model="formInline.patrolPlanName" placeholder="作业项名称"></el-input>
      </el-form-item>
<!--      <el-form-item label="创建时间">-->
<!--        <el-input v-model="formInline.creatTime" placeholder="创建时间"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="巡检类型：">
        <el-select
          v-model="formInline.patrolPlanType"
          value-key="id"
          filterable
          clearable
        >
          <el-option
            v-for="item in optionsList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button @click="reset">清空</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%" :header-cell-style="{background:'#006175',color:'#fff'}" :row-class-name="tableRowClassName">
      <el-table-column label="序号" width="50">
        <template v-slot="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="patrolPlanName" label="方案名称"  align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="patrolPlanDesc" label="方案描述"  align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="assignCount" label="作业项数量"  align="center" width="100px"></el-table-column>
      <el-table-column prop="patrolPlanType" label="巡检类型"  align="center" width="100px"></el-table-column>
      <el-table-column prop="patrolCycles" label="周期（天）"  align="center" width="90px"></el-table-column>
      <el-table-column prop="patrolFrequency" label="次数"  align="center" width="90px"></el-table-column>
      <el-table-column prop="createTime" label="创建时间"  align="center">
        <template v-slot="scope">
          <el-tooltip placement="top">
            <span slot="content">{{ scope.row.createTime }}</span>
            <span class="tooltipClass">{{ scope.row.createTime }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="isUsing" label="使用状态" width="80px">
        <template v-slot="{row}">
          <span :style="{color:row.isUsing == 0?'':'#0ACC00'}">
             {{ row.isUsing == 0 ? '未使用' : '使用中' }}
          </span>
        </template>
      </el-table-column>
      <!--      创建时间-->
      <el-table-column label="操作" width="300px">
        <template v-slot="scope">
          <el-button class="common-btn" @click="getEditor(scope.row)">修改</el-button>
          <el-button class="common-btn" @click="getDetail(scope.row)">详情</el-button>
          <el-button class="delete-btn" @click="getDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="margin-top: 20px"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      :page-size="pagination.pageSize"
      layout="total, sizes, pager, next, jumper"
      :total="pagination.total">
    </el-pagination>
    <addPatrolDialog v-if="DialogPatrolShow" :DialogPatrolShow="DialogPatrolShow" @closeDialog="closeDialogPatrol" :title="titlePatrol" :row="row"></addPatrolDialog>
  </div>
</template>

<script>
import {getPatrolDelete, getPatrolQuery} from '../../api/inspection/pator.js'

import addRiskDialog from "./addRiskDialog";
import addPatrolDialog from "./addPatrolDialog";
import { tableRowClassName } from '../../components/tableStyle';
export default {
  components: {
    addRiskDialog,
    addPatrolDialog
  },
  data() {
    return {
      tableRowClassName,
      option: [],
      tableData: [],
      titlePatrol: '',
      row: '',
      formInline: {
        patrolPlanName: '',
        // creatTime: '',
        patrolPlanType: ''
      },
      pagination: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      DialogComponentShow: false,
      DialogPatrolShow: false,
      optionsList: [
        {
          name: '例行巡视',
          value: '例行巡视'
        },
        {
          name: '特殊巡视',
          value: '特殊巡视'
        },
        {
          name: '专项巡视',
          value: '专项巡视'
        },
        {
          name: '自定义巡视',
          value: '自定义巡视'
        }
      ],
      options: [
        {
          name: '启用',
          value: '1'
        },
        {
          name: '未启用',
          value: '0'
        },
      ]
    };
  },
  mounted() {
    this.getInit()
  },
  methods: {
    _getPlanOpen(row, title) {
      this.titlePatrol = title
      this.DialogPatrolShow = true
      this.row = row
    },
    //新增任务
    addPlan() {
      this._getPlanOpen('', '新增')
    },
    //修改
    getEditor(row) {
      this._getPlanOpen(row, '修改')
    },
    //详情
    getDetail(row) {
      this._getPlanOpen(row, '详情')
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.getInit()
    },
    handleCurrentChange(val) {
      this.pagination.pageNum = val
      this.getInit()
    },
    getDelete(row) {
      this.$confirm('是否删除任务, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          id: row.id
        }
        getPatrolDelete(params).then((res) => {
          if (res.code === 200) {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getInit()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //关闭弹框
    closeDialog() {
      this.DialogComponentShow = false
      this.getInit()
    },
    //关闭弹框
    closeDialogPatrol() {
      this.DialogPatrolShow = false
      this.getInit()
    },
    //列表
    getInit() {
      let params = {
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
        ...this.formInline
      }
      getPatrolQuery(params).then((res) => {
        if (res) {
          this.tableData = res.data
          this.pagination.total = res.total
        }
      })
    },
    onSubmit() {
      this.getInit()
    },
    //手动清空
    reset() {
      this.formInline.patrolPlanName = ''
      this.formInline.patrolPlanType = ''
      this.getInit()
    },
  }
};

</script>

<style scoped>
>>> .el-table{
  margin-top: 0!important;
}
.tooltipClass {
  display: inline-block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
